﻿using PitOfDespair.Dungeon;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace PitOfDespair.Tests
{
    
    
    /// <summary>
    ///This is a test class for PerfectMazeTest and is intended
    ///to contain all PerfectMazeTest Unit Tests
    ///</summary>
    [TestClass()]
    public class PerfectMazeTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for PerfectMaze Constructor
        ///</summary>
        [TestMethod()]
        [DeploymentItem("PitOfDespair.exe")]
        public void PerfectMazeConstructorTest()
        {
            var rnd = new Random(1); 
            int width = 10; 
            int height = 10;
            PerfectMaze_Accessor target = new PerfectMaze_Accessor(rnd, width, height);
            Assert.AreEqual(height, target.height);
            Assert.AreEqual(width, target.width);
            Assert.AreEqual(rnd, target.rnd);
        }

        /// <summary>
        ///A test for FromDirectTranslation
        ///</summary>
        [TestMethod()]
        [DeploymentItem("PitOfDespair.exe")]
        public void FromDirectTranslationTest()
        {
            var rnd = new Random(1);
            var width = 10;
            var height = 10;
            PerfectMaze_Accessor target = new PerfectMaze_Accessor(rnd,width,height ); // TODO: Initialize to an appropriate value
            
            
            Location_Accessor[,] actual;
            actual = target.FromDirectTranslation(width, height,1,1);
            for (int x = 0; x < actual.GetUpperBound(0)+1; x++)
            {
                for (int y = 0; y < actual.GetUpperBound(1)+1; y++)
                {
                    Assert.IsNotNull(actual[x, y], "Null found at " + x + "," + y);
                }
            }
        }

        /// <summary>
        ///A test for Generate
        ///</summary>
        [TestMethod()]
        [DeploymentItem("PitOfDespair.exe")]
        public void GenerateTest()
        {
            var random = new Random(1);
            PerfectMaze_Accessor target = new PerfectMaze_Accessor(random,10,10); 
            
            Location_Accessor[,] actual;
            actual = target.Generate(0,0);
            for (int x = 0; x < actual.GetUpperBound(0)+1; x++)
                for (int y = 0; y < actual.GetUpperBound(1)+1; y++)
                {
                    if (x == 0)
                        Assert.IsTrue(actual[x, y].West != WallType.Open);
                    if (y == 0)
                        Assert.IsTrue(actual[x, y].North != WallType.Open);
                }
            //var 
        }

        /// <summary>
        ///A test for originalTranslation
        ///</summary>
        [TestMethod()]
        [DeploymentItem("PitOfDespair.exe")]
        public void originalTranslationTest()
        {
            int mazeWidth = 8;
            int mazeHeight = 8;
            PerfectMaze_Accessor target = new PerfectMaze_Accessor(new Random(1), mazeWidth,mazeHeight); 
            
            char[,] actual;
            actual = target.originalTranslation(mazeWidth, mazeHeight,0,0);
            for (int x = 0; x <= actual.GetUpperBound(0); x++)
                for (int y = 0; y <= actual.GetUpperBound(1); y++)
                {
                    if (x == 0 || x == actual.GetUpperBound(0))
                        Assert.IsTrue(actual[x, y] == PerfectMaze_Accessor.wall,"["+mazeWidth+","+mazeHeight+"]:actual["+x+","+y+"]");
                    if(y==0 || y==actual.GetUpperBound(1))
                        Assert.IsTrue(actual[x, y] == PerfectMaze_Accessor.wall, "[" + mazeWidth + "," + mazeHeight + "]:actual[" + x + "," + y + "]");
                }
            
        }
    }
}
